package cn.tedu.fresheveryday.mapper;

import cn.tedu.fresheveryday.pojo.entity.User;
import cn.tedu.fresheveryday.pojo.vo.UserSimplePhoneVO;
import cn.tedu.fresheveryday.pojo.vo.UserSimpleVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {
    /**
     * 通过id查询用户的id和昵称，展示商品评论时使用
     * @param id
     * @return
     */
    @Select("select id, nickname from user where id = #{id}")
    UserSimpleVO selectSimpleUserById(String id);

    /**
     * 通过id查询用户信息
     * @param id
     * @return
     */
    @Select("select id, username, password, phone, address, nickname from user where id = #{id}")
    User selectById(String id);

    /**
     * 通过用户名查询用户信息
     * @param username
     * @return
     */
    @Select("select id, username, password, phone, address, nickname from user " +
            "where username = #{username}")
    User selectByUsername(String username);

    /**
     * 添加用户
     * @param user
     */
    @Insert(
            "insert into user (" +
                "id, username, password, phone, nickname" +
            ") values (" +
                "#{id}, #{username}, #{password}, #{phone}, #{nickname}" +
            ")"
    )
    void insert(User user);

    /**
     * 通过手机号查询用户
     * @param phone
     * @return
     */
    @Select("select id, username, phone from user where phone = #{phone}")
    UserSimplePhoneVO selectByPhone(String phone);
}